package formula.business.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.slf4j.LoggerFactory;

@Entity
public class Driver implements java.io.Serializable {

	private static final long serialVersionUID = 3525143366219432958L;
	private final org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());

	private Long id;
	private int version;
	private String lastname;
	private String firstname;
	private Integer age;
	private Date birthdate;
	private Level level;
	private Team team;
	private Boolean isSponsored;
	private Boolean isRetired;
	private Integer victories;

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		logger.debug("in");
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Driver other = (Driver) obj;
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "Driver [id=" + id + ", version=" + version + ", lastname=" + lastname + ", firstname=" + firstname
				+ ", age=" + age + ", birthdate=" + birthdate + "]";
	}

	public Driver() {
	}

	public Driver(String lastname) {
		this.lastname = lastname;
	}

	public Driver(String lastname, String firstname, Integer age) {
		this.lastname = lastname;
		this.firstname = firstname;
		this.age = age;
	}

	@GenericGenerator(strategy = "org.hibernate.id.enhanced.TableGenerator", name = "pilotGen", parameters = {
			@Parameter(name = "table_name", value = "ID_GENERATOR"),
			@Parameter(name = "value_column_name", value = "GEN_VALUE"),
			@Parameter(name = "segment_column_name", value = "GEN_ID"),
			@Parameter(name = "segment_value", value = "PILOT_ID"), @Parameter(name = "increment_size", value = "50"),
			@Parameter(name = "optimizer", value = "pooled") })
	@Id
	@GeneratedValue(generator = "pilotGen")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Version
	@Column(name = "version", nullable = false)
	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}

	@Column(name = "lastname", nullable = false, length = 50, unique = false)
	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	@Column(name = "firstname", nullable = false, length = 50, unique = false)
	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	@Column(name = "age", nullable = false, length = 3, unique = false)
	public Integer getAge() {
		return age;
	}

	public void setBirthdate(Date birthdate) {
		this.birthdate = birthdate;
	}

	@Temporal(TemporalType.DATE)
	public Date getBirthdate() {
		return birthdate;
	}

	public void setLevel(Level level) {
		this.level = level;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	public Level getLevel() {
		return level;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	public Team getTeam() {
		return team;
	}

	public void setTeam(Team _team) {
		team = _team;
	}

	public Boolean getIsSponsored() {
		return isSponsored;
	}

	public void setIsSponsored(Boolean _isSponsored) {
		isSponsored = _isSponsored;
	}

	public Integer getVictories() {
		return victories;
	}

	public void setVictories(Integer _victories) {
		victories = _victories;
	}

	public Boolean getIsRetired() {
		return isRetired;
	}

	public void setIsRetired(Boolean _isRetired) {
		isRetired = _isRetired;
	}
}
